package com.cssw.fyzb.wap.controller;

import com.cssw.fyzb.base.config.JwtConfig;
import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.base.web.util.SecurityKit;
import com.cssw.fyzb.wap.model.dto.*;
import com.cssw.fyzb.wap.model.vo.*;
import com.cssw.fyzb.wap.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author YangYiQun
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @Autowired
    private JwtConfig jwtConfig;

    @ApiOperation("联合登录（第三方）")
    @ApiImplicitParam(name = "dto", value = "联合登录（第三方）", dataType = "UnionLoginDto")
    @PostMapping("unionLogin")
    public AjaxData unionLogin(@RequestBody UnionLoginDto dto) {
        return userService.unionLogin(dto.getOpenid(), dto.getNickName(), dto.getAvatar(), dto.getLoginType());
    }

    @ApiOperation("联合注册（第三方）")
    @ApiImplicitParam(name = "dto", value = "联合登录（第三方）", dataType = "UnionRegisterDto")
    @PostMapping("unionRegister")
    public AjaxData unionRegister(@RequestBody UnionRegisterDto dto) {
        return userService.unionRegister(dto.getOpenid(), dto.getNickName(),
                dto.getAvatar(), dto.getMobile(), dto.getVerifyCode(), dto.getLoginType() );
    }

    @ApiOperation("联合注册(第二步)")
    @ApiImplicitParam(name = "dto", value = "手机号验证码登录参数", dataType = "UnionRegisterAddPwdDto")
    @PostMapping("unionRegisterAddPwd")
    public AjaxData unionRegisterAddPwd(@RequestBody UnionRegisterAddPwdDto dto) {
        return userService.unionRegisterAddPwd(dto.getMobile(), dto.getLoginPwd(), dto.getInviteCode());
    }

    @ApiOperation("QQ登录")
    @ApiImplicitParam(name = "dto", value = "QQ登录", dataType = "LoginByQQDto")
    @PostMapping("loginByQQ")
    public AjaxData loginByQQ(@RequestBody LoginByQQDto dto) {
        return userService.loginByQQ(dto.getOpenid(),
                dto.getUserName(), dto.getNickName(), dto.getProvince(),
                dto.getCity(), dto.getSex(), dto.getAvatar(), dto.getMobile(), dto.getVerifyCode(), dto.getInviteCode());
    }

    @ApiOperation("微信登录")
    @ApiImplicitParam(name = "dto", value = "微信登录", dataType = "LoginByWechatDto")
    @PostMapping("loginByWechat")
    public AjaxData loginByWechat(@RequestBody LoginByWechatDto dto) {
        return userService.loginByWechat(dto.getCode(),
                dto.getMobile(), dto.getVerifyCode(), dto.getInviteCode());
    }

    @ApiOperation(value = "手机号和密码登录")
    @ApiImplicitParam(name = "dto", value = "手机号密码登录参数", dataType = "LoginByPwdDto")
    @PostMapping("loginByPwd")
    public AjaxData<TokenVo> loginByPwd(@RequestBody LoginByPwdDto dto) {
        return userService.loginByPwd(dto.getMobile(), dto.getLoginPwd(), dto.getImsi());
    }

    @ApiOperation(value = "手机号和验证码登录")
    @ApiImplicitParam(name = "dto", value = "手机号验证码登录参数", dataType = "LoginByCodeDto")
    @PostMapping("loginByCode")
    public AjaxData<TokenVo> loginByCode(@RequestBody LoginByCodeDto dto) {
        return userService.loginByCode(dto.getMobile(), dto.getCode(), dto.getImsi());
    }

    @ApiOperation(value = "退出登录")
    @PostMapping("loginOut")
    public AjaxData loginOut() {
        try {
            Long userId = UserContext.getUserId();
            UserContext.remove();
            userService.loginOut(userId);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return AjaxData.success();
    }

    @ApiOperation("用户注册(二步)")
    @ApiImplicitParam(name = "dto", value = "手机号验证码登录参数", dataType = "RegisterAddLoginPwdDto")
    @PostMapping("registerAddLoginPwd")
    public AjaxData registerAddLoginPwd(@RequestBody RegisterAddLoginPwdDto dto) {
        return userService.registerAddLoginPwd(dto.getMobile(), dto.getLoginPwd());
    }

    @ApiOperation("用户注册(一步到位)")
    @ApiImplicitParam(name = "model", value = "用户注册参数", dataType = "RegisterDto")
    @PostMapping("register")
    public AjaxData register(@RequestBody RegisterDto model) {
        return userService.register(
                model.getMobile(), model.getLoginPwd(), model.getInviteCode(),
                model.getVerifyCode()
        );
    }

    @ApiOperation("校验验证码")
    @ApiImplicitParam(name = "dto", value = "trade业务类型 BT010：注册, BT011:登录, BT012:重置密码, BT013: 解绑设备, BT014:修改密码, BT015:修改交易密码", dataType = "VerifyDto")
    @PostMapping("verify")
    public AjaxData verify(@RequestBody VerifyDto dto) {
        return userService.verify(
                dto.getMobile(), dto.getTrade(), dto.getVerifyCode(), dto.getInviteCode()
        );
    }

    @ApiOperation(value = "生成用户邀请码")
    @GetMapping("getInvitCode")
    public AjaxData<InviteCodeVo> getInvitCode() {
        return userService.getInvitCode(UserContext.getUserId());
    }

    @ApiOperation(value = "生成用户星光码")
    @GetMapping("getTransferCode")
    public AjaxData<TransferCodeVo> getTransferCode() {
        return userService.getTransferCode(UserContext.getUserId());
    }

    @ApiOperation(value = "获取用户信息")
    @GetMapping("getUserInfo")
    public AjaxData<UserInfoVo> getUserInfo() {
        return userService.getUserInfo(UserContext.getUserId());
    }

    @ApiOperation(value = "获取公开用户信息")
    @GetMapping("getPublicUserInfo")
    @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "query", dataType = "int", required = true)
    public AjaxData<UserInfoVo> getPublicUserInfo(Long userId) {
        return userService.getPublicUserInfo(userId);
    }

    @ApiOperation(value = "获取粉丝数量")
    @GetMapping("getFansNum")
    public AjaxData<FansNumVo> getFansNum() {
        return userService.getFansNum(UserContext.getUserId());
    }

    @ApiOperation(value = "获取他人粉丝数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("getFansNumForOther")
    public AjaxData<FansNumVo> getFansNumForOther(Long userId) {
        return userService.getFansNum(userId);
    }


    @ApiOperation(value = "获取关注数量")
    @GetMapping("getFollowNum")
    public AjaxData<FollowNumVo> getFollowNum() {
        return userService.getFollowNum(UserContext.getUserId());
    }


    @ApiOperation(value = "获取他人关注数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("getFollowNumForOther")
    public AjaxData<FollowNumVo> getFollowNumForOther(Long userId) {
        return userService.getFollowNum(userId);
    }

    @ApiOperation(value = "获取好友数量")
    @GetMapping("getFriendNum")
    public AjaxData<FriendNumVo> getFriendNum() {
        return userService.getFriendNum(UserContext.getUserId());
    }


    @ApiOperation(value = "获取他人好友数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("getFriendNumForOther")
    public AjaxData<FriendNumVo> getFriendNumForOther(Long userId) {
        return userService.getFriendNum(userId);
    }

    @ApiOperation(value = "获取粉丝分页列表")
    @RequestMapping(value = "/listFans", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<PublicUserInfoVo> listFans(int pageNumber, int pageSize) {
        return userService.listFans(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "获取他人粉丝分页列表")
    @RequestMapping(value = "/listFansForOther", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "他人用户标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<PublicUserInfoVo> listFansForOther(Long userId, int pageNumber, int pageSize) {
        return userService.listFans(userId, pageNumber, pageSize);
    }

    @ApiOperation(value = "获取关注列表")
    @RequestMapping(value = "/listFollow", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<PublicUserInfoVo> listFollow(int pageNumber, int pageSize) {
        return userService.listFollow(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "获取他人关注列表")
    @RequestMapping(value = "/listFollowForOther", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "他人用户标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<PublicUserInfoVo> listFollowForOther(Long userId, int pageNumber, int pageSize) {
        return userService.listFollow(userId, pageNumber, pageSize);
    }

    @ApiOperation(value = "获取好友分页列表")
    @RequestMapping(value = "/listFriend", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<PublicUserInfoVo> listFriend(int pageNumber, int pageSize) {
        return userService.listFriend(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "获取他人好友分页列表")
    @RequestMapping(value = "/listFriendForOther", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "他人用户标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<PublicUserInfoVo> listFriendForOther(Long userId, int pageNumber, int pageSize) {
        return userService.listFriend(userId, pageNumber, pageSize);
    }

    @ApiOperation("获取邀请者信息")
    @GetMapping("getSupInfo")
    public AjaxData<UserInfoVo> getSupInfo() {
        return userService.getSupInfo(UserContext.getUserId());
    }

    @ApiOperation("重置密码")
    @ApiImplicitParam(name = "dto", value = "重置交易密码", dataType = "ResetPwdDto")
    @PostMapping("resetPwd")
    public AjaxData resetPwd(@RequestBody ResetPwdDto dto) {
        return userService.resetPwd(
                dto.getMobile(), dto.getVerify(), dto.getLoginPwd()
        );
    }

    @ApiOperation("重置交易密码")
    @ApiImplicitParam(name = "dto", value = "重置交易密码参数", dataType = "ResetTradePwdDto")
    @PostMapping("resetTradePwd")
    public AjaxData resetTradePwd(@RequestBody ResetTradePwdDto dto) {
        return userService.resetTradePwd(
                dto.getMobile(), dto.getVerify(), dto.getLoginPwd()
        );
    }

    @ApiOperation("修改密码(二步)")
    @ApiImplicitParam(name = "dto", value = "修改密码(二步)", dataType = "UpdateLoginPwdDto")
    @PostMapping("updateLoginPwd")
    public AjaxData updateLoginPwd(@RequestBody UpdateLoginPwdDto dto) {
        return userService.updateLoginPwd(dto.getMobile(), dto.getLoginPwd());
    }

    @ApiOperation("修改交易密码(二步)")
    @ApiImplicitParam(name = "dto", value = "修改交易密码(二步)", dataType = "UpdateTradePwdDto")
    @PostMapping("updateTradePwd")
    public AjaxData updateTradePwd(@RequestBody UpdateTradePwdDto dto) {
        return userService.updateTradePwd(dto.getMobile(), dto.getTradePwd());
    }

    @ApiOperation("重新绑定设备信息")
    @ApiImplicitParam(name = "dto", value = "更改绑定设备参数", dataType = "RebindDeviceDto")
    @PostMapping("rebindDevice")
    public AjaxData rebindDevice(@RequestBody RebindDeviceDto dto) {
        return userService.rebindDevice(
                dto.getMobile(), dto.getCode(), dto.getImsi()
        );
    }

    @ApiOperation("解除绑定设备信息")
    @ApiImplicitParam(name = "dto", value = "更改绑定设备参数", dataType = "UnbindDeviceDto")
    @PostMapping("unbindDevice")
    public AjaxData unbindDevice(@RequestBody UnbindDeviceDto dto) {
        return userService.unbindDevice(
                dto.getMobile(), dto.getCode(), dto.getImsi()
        );
    }

    @ApiOperation("实名认证")
    @ApiImplicitParam(name = "dto", value = "实名认证参数", dataType = "UserAuthDto")
    @PostMapping("userAuth")
    public AjaxData userAuth(@RequestBody UserAuthDto dto, HttpServletRequest request) throws Exception {
        String token = request.getHeader(jwtConfig.getHeader());
        logger.info("m:" + dto.getM_key());
        logger.info("s:" + dto.getS_key());
        if (!SecurityKit.checkToken(dto.getM_key(), dto.getS_key(), token)) {
//            throw new RobotException();
        }
        return userService.userAuth(UserContext.getUserId(), dto.getName(), dto.getIdCard());
    }

    //    @ApiOperation("人脸认证")
//    @ApiImplicitParam(name = "dto", value = "人脸认证参数", dataType = "FaceAuthDto")
//    @PostMapping("faceAuth")
    public AjaxData faceAuth(@RequestBody FaceAuthDto dto, HttpServletRequest request) throws Exception {
        String token = request.getHeader(jwtConfig.getHeader());
        logger.info("m:" + dto.getM_key());
        logger.info("s:" + dto.getS_key());
        if (!SecurityKit.checkToken(dto.getM_key(), dto.getS_key(), token)) {
//            throw new RobotException();
        }

        return userService.faceAuth(UserContext.getUserId(), dto.getUrl());
    }

    @ApiOperation("支付认证")
    @PostMapping("payAuth")
    public AjaxData payAuth() {
        return userService.payAuth(UserContext.getUserId());
    }

    @ApiOperation("修改用户头像")
    @ApiImplicitParam(name = "dto", value = "更新头像参数", dataType = "UpdateAvatarDto")
    @PostMapping("updateAvatar")
    public AjaxData updateAvatar(@RequestBody UpdateAvatarDto dto) {
        return userService.updateAvatar(UserContext.getUserId(), dto.getUrl());
    }

    @ApiOperation("修改昵称")
    @ApiImplicitParam(name = "dto", value = "更新昵称", dataType = "UpdateNickNameDto")
    @PostMapping("UpdateNickName")
    public AjaxData UpdateNickName(@RequestBody UpdateNickNameDto dto) {
        return userService.UpdateNickName(UserContext.getUserId(), dto.getNickName());
    }

    @ApiOperation("修改个性签名")
    @ApiImplicitParam(name = "dto", value = "更新昵称", dataType = "UpdateSignDto")
    @PostMapping("UpdateSign")
    public AjaxData UpdateSign(@RequestBody UpdateSignDto dto) {
        return userService.UpdateSign(UserContext.getUserId(), dto.getSign());
    }

    @ApiOperation("修改生日")
    @ApiImplicitParam(name = "dto", value = "更新昵称", dataType = "UpdateBirthdayDto")
    @PostMapping("UpdateBirthday")
    public AjaxData UpdateBirthday(@RequestBody UpdateBirthdayDto dto) {
        return userService.UpdateBirthday(UserContext.getUserId(), dto.getBirthday());
    }

    @ApiOperation("修改性别")
    @ApiImplicitParam(name = "dto", value = "更新昵称", dataType = "UpdateSexDto")
    @PostMapping("UpdateSex")
    public AjaxData UpdateSex(@RequestBody UpdateSexDto dto) {
        return userService.UpdateSex(UserContext.getUserId(), dto.getSex());
    }

    @ApiOperation("获取图形验证码")
    @GetMapping("getCaptcha")
    public AjaxData getCaptcha() {
        return userService.getCaptcha();
    }

    @ApiOperation("获取用户统计信息")
    @GetMapping("getUserStat")
    public AjaxData getUserStat() {
        return userService.getUserStat(UserContext.getUserId());
    }

    @ApiOperation("获取短信验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "trade", value = "业务类型 BT010：注册, BT011:登录, BT012:重置密码, BT013: 解绑设备, BT014:修改密码, BT015:修改交易密码", paramType = "query", dataType = "string")
    })
    @GetMapping("getVerify")
    public AjaxData getVerify(String mobile, String trade) {
        return userService.getVerify(mobile, trade);
    }

    @ApiOperation("查询最新版本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appName", value = "App名称(fyzb)", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "App类型(ios,android)", paramType = "query", dataType = "string"),
    })
    @GetMapping("getAppVersion")
    public AjaxData getAppVersion(String appName, String type) {
        return userService.getAppVersion(appName, type);
    }


    @ApiOperation("更新最新版本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "版本更新", dataType = "UpdateAppVersionDto")

    })
    @PostMapping("updateAppVersion")
    public AjaxData updateAppVersion(@RequestBody UpdateAppVersionDto dto) {
        return userService.updateAppVersion(
                dto.getName(), dto.getAppName(), dto.getAppUrl1(), dto.getAppUrl2(),
                dto.getVersionName(), dto.getVersionCode()
        );
    }

    @ApiOperation("腾讯云人脸核身-送信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "腾讯云人脸核身", dataType = "TecentFaceAuthSendDto")

    })
    @PostMapping("tecentFaceAuthSend")
    public AjaxData tecentFaceAuthSend(@RequestBody TecentFaceAuthSendDto dto) {
        return userService.tecentFaceAuthSend(UserContext.getUserId(), dto.getUserName(), dto.getIdCard(), dto.getProvinceCode(), dto.getCityCode(), dto.getDistrictCode());
    }

    @ApiOperation("腾讯云人脸核身-查信息")
    @ApiImplicitParam(name = "orderNo", value = "订单号", paramType = "query", dataType = "string")
    @GetMapping("tecentFaceAuthQuery")
    public AjaxData tecentFaceAuthQuery(String orderNo) {
        return userService.tecentFaceAuthQuery(UserContext.getUserId(), orderNo);
    }

    @ApiOperation("省市区")
    @GetMapping("getDistrictTree")
    public AjaxPage getDistrictTree() {
        return userService.getDistrictTree();
    }

    @ApiOperation(value = "关注用户")
    @RequestMapping(value = "/follow", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData follow(@RequestBody FollowUserDto dto) {
        return userService.follow(UserContext.getUserId(), dto.getUserId(), dto.getType());
    }

    @ApiOperation("实名认证信息")
    @GetMapping("queryUserAuthInfo")
    public AjaxData<UserAuthInfo> queryUserAuthInfo() {
        return userService.queryUserAuthInfo(UserContext.getUserId());
    }

    @ApiOperation("搜索用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", value = "关键字", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @GetMapping("searchUser")
    public AjaxPage<SearchUserVo> searchUser(String key, Integer pageNumber, Integer pageSize) {
        return userService.searchUser(UserContext.getUserId(), key, pageNumber, pageSize);
    }

    @ApiOperation("直播内查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播间标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "userId", value = "被查询用户标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("getUserForLive")
    public AjaxData<UserForLiveVo> getUserForLive(Long liveId, Long userId) {
        return userService.getUserForLive(UserContext.getUserId(), liveId, userId);
    }

    @ApiOperation("查询他人用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "被查询用户标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("getUserForOther")
    public AjaxData<UserOtherVo> getUserForOther(Long userId) {
        return userService.getUserForOther(UserContext.getUserId(), userId);
    }

    @ApiOperation("获取联合token")
    @PostMapping("getFederationToken")
    public AjaxData getFederationToken(@RequestBody CredentialsDto dto) {
        return userService.getFederationToken(dto.getPolicy());
    }

    @ApiOperation("根据号码查询用户标识")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("checkMobile")
    public AjaxData<UserIdVo> checkMobile(String mobile) {
        return userService.checkMobile(mobile);
    }

    @ApiOperation("获取AES密文")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "plaintext", value = "密码明文", paramType = "query", dataType = "string", required = true)
    })
    @GetMapping("getAesCiphertext")
    public AjaxData getAesCiphertext(String plaintext) {
        return userService.getAesCiphertext(plaintext);
    }

    @ApiOperation("检查授权许可")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", dataType = "string", required = true)
    })
    @GetMapping("checkLicence")
    public AjaxData checkLicence(String code) {
        return userService.checkLicence(code);
    }

    @ApiOperation("开通vip会员支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "支付开通vip会员参数", dataType = "OpenUserVipPayDto")
    })
    @PostMapping("openVipPay")
    @ResponseBody
    public AjaxData openVipPay(@RequestBody OpenUserVipPayDto dto) {
        return userService.openVipPay(UserContext.getUserId(), dto.getPayWay(), dto.getExpend());
    }

    @ApiOperation("更新福音号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "更新福音号参数", dataType = "UpdateFyNoDto")
    })
    @PostMapping("updateFyNo")
    @ResponseBody
    public AjaxData updateFyNo(@RequestBody UpdateFyNoDto dto) {
        return userService.updateFyNo(UserContext.getUserId(), dto.getFyNo());
    }

    @ApiOperation("更新头像挂件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "更新头像挂件参数", dataType = "UpdatePendantUrlDto")
    })
    @PostMapping("updatePendantUrl")
    @ResponseBody
    public AjaxData updatePendantUrl(@RequestBody UpdatePendantUrlDto dto) {
        return userService.updatePendantUrl(UserContext.getUserId(), dto.getPendantId(), dto.getType());
    }

    @ApiOperation("重置头像挂件")
    @PostMapping("resetPendantUrl")
    @ResponseBody
    public AjaxData resetPendantUrl() {
        return userService.resetPendantUrl(UserContext.getUserId());
    }


    @ApiOperation("查询头像挂件列表")
    @GetMapping("listAvatarPendantDef")
    public AjaxPage<AvatarPendantDefVo> listAvatarPendantDef() {
        return userService.listAvatarPendantDef(UserContext.getUserId());
    }

}
